package com.idione.model;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.idione.activities.R;
import com.idione.util.LogUtil;

public class SeeQuestionAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<StructSeeQuestion> ssq;
	private Typeface tft, tfs;

	public SeeQuestionAdapter(Context c, ArrayList<StructSeeQuestion> ssq) {
		context = c;
		this.ssq = ssq;

		tft = LogUtil.getTypeFaceTitle(c);
		tfs = LogUtil.getTypeFaceSubtitle(c);
	}

	@Override
	public int getCount() {
		log("getCount(" + ssq.size() + ")");
		return ssq.size();
	}

	@Override
	public Object getItem(int position) {
		log("getItem(int " + position + ")");

		if (0 <= position && position < this.getCount())
			return ssq.get(position);
		else
			return null;
	}

	@Override
	public long getItemId(int position) {
		log("getItemId(int " + position + ")");
		return ssq.get(position).getId();
	}

	// create a new ImageView for each item referenced by the Adapter
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		log("getView()");

		View rowView;
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			rowView = inflater.inflate(R.layout.struct_see_question, parent, false);
		} else {
			rowView = convertView;
		}
		
		TextView title = (TextView) rowView.findViewById(R.id.LblTitle);
		TextView questionText = (TextView) rowView.findViewById(R.id.LblQuestionText);
		ImageView questionImage = (ImageView) rowView.findViewById(R.id.ImgViewImageQuestion);

		log("position : " + position);
		log("ssq[position].getNumberQuestionTitle() : " + ssq.get(position).getNumberQuestionTitle());

		title.setText(ssq.get(position).getNumberQuestionTitle());
		title.setTypeface(tft);
		title.setTextColor(context.getResources().getColor(R.color.Orange));

		questionText.setText(ssq.get(position).getQuestionText());
		questionText.setTypeface(tfs);

		questionImage.setImageDrawable(ssq.get(position).getDrawable());
		rowView.setId(ssq.get(position).getId());

		return rowView;
	}

	/*----------------------------------------------------------------------------------*
	 * Log 																				*
	 *----------------------------------------------------------------------------------*/
	private final String LOGTAG = "LogsClass " + this.getClass().getName();
	private void log(String method) {
		if (LogUtil.modelLog)
			Log.i(LOGTAG, "... method : " + this.getClass().getSimpleName() + "." + method);
	}
}